/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sgsmcan.Servlet;


import com.sgsmcan.Hibernate.HibernateUtil;
import com.sgsmcan.Utils.Utilitario;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.hibernate.Session;


/**
 *
 * @author user
 */
public class HibernateListener implements ServletContextListener{
    private final String clase ="[HibernateListener]";
    
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        Utilitario.LOG.info(clase + " Iniciando Servlet de Hibernate");
        Session session = HibernateUtil.getSessionFactory().openSession();
        if(session == null){
            Utilitario.LOG.info(clase + " Error al iniciar el servlet de Hibernate");
        }else{
            session.close();
            
            Utilitario.LOG.info(clase + " Corriendo exitosamente Hibernate");
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        HibernateUtil.getSessionFactory().close();
    }
    
}
